-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
43 lines (30 loc) · 858 Bytes
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
String num;
while (true) {
num = sc.next();
if (num.equals("0"))
break;
int j = 0;
int res = 0;
int tam = num.length();
int[] vet = new int[tam];
for (int i = tam; i >= 1; i--) {
vet[j] = fatorial(i);
j++;
}
for (int i = 0; i < tam; i++)
res += (num.charAt(i) - 48) * vet[i];
System.out.println(res);
}
sc.close();
}
public static int fatorial(int n) {
if (n == 0)
return 1;
return fatorial(n - 1) * n;
}
}